# -*- coding: utf-8 -*-
from django.db import models
from django.utils import timezone


class Tag(models.Model):
    GREEN = 'green'
    BLUE = 'blue'
    RED = 'red'
    GRAY = 'gray'
    AQUA = 'Aqua'
    COLOR_CHOICES = (
        (GREEN, 'green'),
        (BLUE, 'blue'),
        (RED, 'red'),
        (GRAY, 'gray'),
        (AQUA, 'Aqua'),
    )
    name = models.CharField(max_length=35, verbose_name='名称')
    color = models.CharField(max_length=10, default=AQUA, choices=COLOR_CHOICES, verbose_name='颜色')

    class Meta:
        verbose_name = '标签'
        verbose_name_plural = '标签'

    def __unicode__(self):
        return self.name


class Category(models.Model):
    name = models.CharField(max_length=50, verbose_name='名称')
    desc = models.CharField(max_length=100, null=True, blank=True, verbose_name='描述')
    parent = models.ForeignKey('self', null=True, blank=True, verbose_name='父级类目')

    class Meta:
        verbose_name = '分类'
        verbose_name_plural = '分类'

    def __unicode__(self):
        return self.name


class Article(models.Model):
    title = models.CharField(max_length=100, verbose_name='标题')
    author = models.CharField(max_length=50, verbose_name='作者')
    digest = models.CharField(max_length=150, verbose_name='摘要')
    img = models.URLField(max_length=150, blank=True, null=True, verbose_name='主图')
    from_url = models.URLField(max_length=100, blank=True, null=True, verbose_name='来源')
    content = models.TextField(verbose_name='内容')
    tags = models.ManyToManyField(Tag, verbose_name='标签')
    categories = models.ManyToManyField(Category, verbose_name='类目')
    view_count = models.IntegerField(verbose_name='点击数', default=1)
    create_at = models.DateTimeField(verbose_name='创建时间时间', auto_now_add=True)
    update_at = models.DateTimeField(verbose_name='更新时间', auto_now=True)

    class Meta:
        verbose_name = '文章'
        verbose_name_plural = '文章'

    def __unicode__(self):
        return self.title


class Link(models.Model):
    name = models.CharField(max_length=50, verbose_name='显示名称')
    url = models.URLField(max_length=100, verbose_name='URL地址')
    weight = models.IntegerField(default=0, verbose_name='权重')

    class Meta:
        verbose_name = '友情链接'
        verbose_name_plural = '友情链接'

    def __unicode__(self):
        return self.name


class Menu(models.Model):
    name = models.CharField(max_length=50, verbose_name='菜单显示名称')
    url = models.URLField(max_length=100, verbose_name='URL地址')
    weight = models.IntegerField(default=0, verbose_name='权重')

    class Meta:
        verbose_name = '首页菜单'
        verbose_name_plural = '首页菜单'

    def __unicode__(self):
        return self.name